package com.zhuiyun.project.api.recording.mapper;

import com.zhuiyun.project.api.recording.entiy.TransactionHistory;
import com.zhuiyun.project.api.recording.model.TransactionHistoryModel;
import com.zhuiyun.project.common.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

@Mapper
public interface TransactionHistoryMapper extends BaseMapper<TransactionHistory> {
    @Select("<script>" +
            "SELECT t.*, s.user_name from transaction_history t LEFT JOIN sys_user s   ON s.phone = t.recharge_user_phone where  1=1 " +
            "<when test = 'userName != &quot;&quot; and userName != null'>" +
            " and s.user_name LIKE CONCAT('%', #{userName}, '%')  </when>" +
            "</script> ")
    List<TransactionHistoryModel> selectTransactionHistoryAndUser(@Param("userName") String userName);

    /**
     * @param phone
     * @param productId
     * @return
     */
    @Select("select count(1) from  transaction_history where product_id=#{productId} and recharge_user_phone=#{phone}")
    int getTransactionHistoryById(String phone, Integer productId);

    @Select("select t.*, s.flag ,s.lottery_no ,s.phone_number from transaction_history t LEFT JOIN submit_record s on t.product_id = s.id where  t.product_id IS NOT NULL and s.lottery_no = #{lastLotteryNo} and status = 0 and separate_flag!=1")
    List<TransactionHistoryModel> getTransactionByProductIdAndLotteryNo(String lastLotteryNo);

    @Update("update transaction_history set separate_flag =1 ,state =#{state} where id=#{id}")
    void updateSeparateFlag(Integer id,String state);
}
